-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing some structure for model method bodies #3571
base: main
Are you sure you want to change the base?
Conversation
restricted to ifs and intermediate variables
and spotlessing
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3571 +/- ##
============================================
- Coverage 38.39% 38.39% -0.01%
- Complexity 17238 17239 +1
============================================
Files 2098 2098
Lines 127324 127346 +22
Branches 21442 21444 +2
============================================
+ Hits 48886 48891 +5
- Misses 72427 72441 +14
- Partials 6011 6014 +3 ☔ View full report in Codecov by Sentry. |
My questions would also be:
Maybe we should add a |
Because thus jml model method bodies can remain purely logical expressions and their definition can be directly expanded into the sequent. That is a fundamental asset of model methods as they are implemented in KeY (like related constructs in other verification frameworks). Dealing with loops in particular would make this impossible. This was driven by trying to relax notation while keeping the verification-system power of the type definitions. How does the JavaDL-definition axiom or taclet for model methods look like in jmlparser?
I think actually, it does. In KeY, however, the expansion mechanism for non-model methods, is conservative and uses [] box-semantics to be on the safe side.
I would refrain from putting jml model methods into modalities, It's their power to define functions directly. I would be happy to intrdoduce ghost methods that can use any code. They do not even need to be pure. |
@@ -7,6 +7,8 @@ lexer grammar JmlLexer; | |||
// needed for double literals and ".." | |||
private int _lex_pos; | |||
|
|||
private boolean parensEndExpr = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we reached a point in which we should rather rewrite the lexer w/o using modes for top-level and expr-mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these modes are really necessary in the lexer.
Yes one could name a variable "ensures", and write ensures ensures > 4;
. But this is fully confusing.
I would be in favour of allowing backticks in these cases for turning keywords into identifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I did this, I came from the jmllang
lexer/parser (Java+JML in ANTLR), where I used this heavily.
The advantage is, that the error messages are a little bit better. ("Expected identifier" vs "Expected identifier, ensures, requires, ... "). But the price is a complicated lexer.
I would now get rid of it, and introduce a grammar rule:
identifier: IDENTIFIER | MODEL | ENSURES | REQUIRES | ...;
I would keep modes for Strings & Co.
Do we not have (proposed) backticks for JavaDL escape of complete terms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not have (proposed) backticks for JavaDL escape of complete terms?
Maybe, don't know. Was that not (* ... *)
?
Actually I even actively avoid ensures ensures > 4;
to be legal.
Escaping the identifier ensures seems like a natural thing to do.
Languages like SMT, SQL, ... have support for this, with explicit escapes.
(I had it in ivil, too. It was a simple addition to the parser.)
While it is a discussion worth having, it is beyond this PR that will have to accommodate to the current parser framework; and does so with not so much extra overhead.
(Just that an extra ")" leads back to toplevel mode if that is enabled -- this condition might probably even be dropped, but I wanted to be conservative.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so complicated: #3572
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently we do not show these long "expected ....." lists anyway in our syntax error to string conversion anyway, so this may work well (eventually).
String name = varCtx.IDENT().getText(); | ||
SLExpression expr = accept(varCtx.expression()); | ||
Term term = expr.getTerm(); | ||
LogicVariable logVar = new LogicVariable(new Name(name), term.sort()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens on a name clash?
var x = 1; var x = 2;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. This is currently allowed. You can write var x = 1; x = 2;
which should be legal.
It would be nicer to ensure:
- If keyword "var" is present, no variable x must be in namespace
- If no keyword var is present, there is a variable x of compatible type present in the namespace.
It is not required technically, and everything is welldefined in either case. But it would violate Java principles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add this.
Intended Change
This is a new feature request by users that wanted to use model methods.
The PR introduces method bodies that allow some statements. It is limited to
This is still rather limited but allows you to structure your code already quite a bit.
The restrictions are:
var
(due to a restriction in the lexer/parser)The only thing that needs to be done is then to interpret these structures into a term.
My running example is the following which explains itself:
Plan
Type of pull request
Ensuring quality
Additional information and contact(s)
The contributions within this pull request are licensed under GPLv2 (only) for inclusion in KeY.